package com.yidu.DatelessManagement.mapper;
import com.yidu.BusinessParament.entity.Fund;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import com.yidu.DatelessManagement.entity.ProvisionOfIncome;

import java.util.List;
import java.util.Map;

/**
 * @author 周楠櫻木
 * @version 1.0
 * @date 2023/2/5
 */
@Mapper
public interface ProvisionOfIncomeMapper {
    /**
     * 现金库存join现金账户查询所有现金利息
     * @param map
     * @return
     */
    //c.bankName,c.accountName,c.stockpileType,c.bearingTime,c.cardRetes,cs.money,cs.countTime
    @Select("SELECT *, (money*(cardRetes/if(bearingTime = 1,'365','366'))/100) cashLiXi FROM cashStock cs RIGHT JOIN cash c ON cs.cashId = c.cashId where 1=1 ${sqlWhere} limit #{page},#{limit}")
    List<ProvisionOfIncome> selectCashInterest(Map map);

    @Select("select count(*) from cashStock cs join cash c on cs.cashId = c.cashId where 1=1 ${sqlWhere}")
    int getSumRow(Map map);

    /**
     * 债券利息查询所有
     * @param map
     * @return
     */
    @Select("SELECT b.*,ss.DATE,ss.DATE,ss.quantity, ((delayDate * 0.01 / 365 * 100) * quantity) bondLiXi,ss.`fundId`,ss.`securityId` FROM bond b LEFT JOIN securityStock ss ON b.bondId=ss.securityStockId where 1=1 ${sqlWhere} limit #{page},#{limit}")
    List<ProvisionOfIncome> selectBondInterest(Map map);

    @Select("SELECT b.*,ss.DATE,ss.quantity, ((delayDate * 0.01 / 365 * 100) * quantity) bondLiXi,ss.`fundId`,ss.`securityId` FROM bond b JOIN securityStock ss ON b.bondId=ss.securityStockId where 1=1 ${sqlWhere}")
    List<ProvisionOfIncome> getSumRowBond(Map map);

    /**
     * 两费查询所有
     * @param map
     * @return
     */
    @Select("select * from fund where 1=1 ${sqlWhere} limit #{page},#{limit}")
    List<ProvisionOfIncome> selectFund(Map map);
    @Select("select count(*) from fund where 1=1 ${sqlWhere}")
    public int SelectFundCount(Map map);





    /**
     * 获取指定时间的资产净值
     *
     * @param createTime 时间
     * @return double 资产净值
     */
    @Select("select capital\n" +
            "from netWorth\n" +
            "where createTime = #{createTime}\n" +
            "  and projectName = '资产净值'")
    Double getChanJinZhi(String createTime);

    /**
     * 获取指定时间的资产净值行数
     *
     * @param createTime 时间
     * @return int 返回查询到的行数
     */
    @Select("select count(*)\n" +
            "from netWorth\n" +
            "where createTime = #{createTime}\n" +
            "  and projectName = '资产净值'")
    int getChanJinZhiHangShu(String createTime);

    /**
     * 查询基金创立时间
     *
     * @param map 数据映射集合
     * @return int 查询到的行数
     */
    @Select("select count(*)\n" +
            "from fund\n" +
            "where fundId = #{fundId}\n" +
            "and foundTime <= #{foundTime}")
    int getJiJinChuangLiShiJian(Map<String, Object> map);

    /**
     * 通过查询基金规模
     *
     * @param fundId 数据映射集合
     * @return double 基金规模
     */
    @Select("select fundScale\n" +
            "from fund\n" +
            "where fundId = #{fundId}")
    double getJiJinGuiMo(String fundId);

    /**
     * 判断今日是否为基金成立日
     *
     * @param map 数据映射集合
     * @return int 执行成功的行数
     */
    @Select("select count(*)\n" +
            "from fund\n" +
            "where fundId = #{fundId}\n" +
            "and foundTime = #{foundTime}")
    int panDuanJinRiShiFouWeiJiJingChenLiRi(Map map);

    /**
     * 根据id查询基金
     * @param fundId 基金id
     * @return
     */
    @Select("select * from fund where fundId = #{fundId}")
    Fund provisionOfIncomeSelectFund(String fundId);


    @Select("select fundScale from fund")
    List<ProvisionOfIncome> SelectFundScale();
}
